package cn.jorian.framework.service;

import cn.jorian.framework.entity.User;
import cn.jorian.framework.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.jws.soap.SOAPBinding;
import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public User saveUser(User user) {
        return userRepository.save(user);
    }

    public List<User> findByEmail(String email) {
        return userRepository.findByEmail(email);
    }

    public Page<User> findByAll() {
        Pageable pageable = PageRequest.of(0, 2);
       return userRepository.findAll(pageable);
    }

    public List<User> getByAge(Integer age) {
        return userRepository.findByAgeLessThan(age);
    }
}
